/*
Example 5.4
 Control a toy remote control car with arduino - figure eight
 Chapter Five @ http://www.tronixstuff.com/tutorials
 */

int forward = 12;
int left = 9;
int right = 7;
int del = 5000;


void setup()
{
  pinMode(forward, OUTPUT);
  pinMode(left, OUTPUT);
  pinMode(right, OUTPUT);
}

// to make creating the car's journey easier, here are some functions

void goleft(int runtime)
{
  digitalWrite(left, HIGH);  // tell the steering to turn left
  digitalWrite(forward, HIGH); // move the car forward 
  delay(runtime);
  digitalWrite(forward, LOW);
  digitalWrite(left, LOW);  // tell the steering to straighen up
}

void goright(int runtime)
{
  digitalWrite(right, HIGH);  // tell the steering to turn right
  digitalWrite(forward, HIGH); // move the car forward 
  delay(runtime);
  digitalWrite(forward, LOW);
  digitalWrite(right, LOW);  // tell the steering to straighen up
}

void goforward(int runtime)
// run the drive motor for "runtime" milliseconds
{
  digitalWrite(forward, HIGH);  // start the drive motor forwards
  delay(runtime);
  digitalWrite(forward, LOW); // stop the drive motor
}

void loop()
{
  goforward(1000);
  goleft(1000);
  goright(1000);
}

